﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows;
using HelloWindowsPhoneMVC.Model;
using HelloWindowsPhoneMVC.Services;
using HelloWindowsPhoneMVC.ViewModels.Home;
using WindowsPhoneEssentials.Threading;
using WindowsPhoneMVC;
using WindowsPhoneMVC.ActionResults;
using WindowsPhoneMVC.Framework;

namespace HelloWindowsPhoneMVC.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Main()
        {
            return Page(new MainViewModel());
        }

        public ActionResult SayHelloTo(string arg)
        {
            Execute.OnUIThreadSync(() => MessageBox.Show("Hi " + arg));

            return Nothing();
        }

        public ActionResult DebugPage()
        {
            var parameter = new SomeClass { Message = "From Controller" };
            var parameter2 = new SomeClass { Message = "From Controller, param2" };
            return Page(new DebugPageViewModel(parameter, parameter2));
        }

        public ActionResult AboutDialog(ItemFromList datacontext)
        {
            LoadingMessage("Let's pretend it is a long running action");
            Thread.Sleep(2000);
            LoadingMessage("This is the action execution progress");
            Thread.Sleep(2000);
            LoadingMessage("So you can put something like '65% left' here");
            Thread.Sleep(2000);
            LoadingMessage("Actions are also cancellable, by pressing the back button");
            Thread.Sleep(2000);

            LoadingMessage("and here is About Page");
            Thread.Sleep(2000);

            // Specifying view name is not required if view name is the same as controller action name
            return Page(new AboutDialogViewModel());
        }

        public ActionResult AppConnect(AppConnectParameters appConnectParameters)
        {
            //The following parameters are used to describe a place card:
            //PlaceName: The name of the place
            //PlaceLatitude: The latitude of the place
            //PlaceLongitude: The longitude of the place
            //PlaceAddress: The address of the place
            //Category: A comma-delineated list of extensions related to the place

            return RedirectTo<HomeController>("AppConnectRedirect", appConnectParameters.PlaceName);
        }

        public ActionResult AppConnectRedirect(string placeName)
        {
            return Page((object)placeName);
        }

        public ActionResult AppSettingsPage()
        {
            return Nothing();
        }

        public ActionResult DeepLinkPage(IDictionary<string, string> arg)
        {
            return Page();
        }
    }
}
